<?php

declare (strict_types=1);

namespace magein\pay\extension;

use Alipay\EasySDK\Payment\Page\Client;

class AliSdkPage extends Client
{
    /**
     *
     * 修改page类型请求的method为get
     * @param $subject
     * @param $outTradeNo
     * @param $totalAmount
     * @param $returnUrl
     * @return mixed
     */
    public function pay($subject, $outTradeNo, $totalAmount, $returnUrl)
    {
        $systemParams = [
            "method" => "alipay.trade.page.pay",
            "app_id" => $this->_kernel->getConfig("appId"),
            "timestamp" => $this->_kernel->getTimestamp(),
            "format" => "json",
            "version" => "1.0",
            "alipay_sdk" => $this->_kernel->getSdkVersion(),
            "charset" => "UTF-8",
            "sign_type" => $this->_kernel->getConfig("signType"),
            "app_cert_sn" => $this->_kernel->getMerchantCertSN(),
            "alipay_root_cert_sn" => $this->_kernel->getAlipayRootCertSN()
        ];
        $bizParams = [
            "subject" => $subject,
            "out_trade_no" => $outTradeNo,
            "total_amount" => $totalAmount,
            "product_code" => "FAST_INSTANT_TRADE_PAY"
        ];
        $textParams = [
            "return_url" => $returnUrl
        ];
        $sign = $this->_kernel->sign($systemParams, $bizParams, $textParams, $this->_kernel->getConfig("merchantPrivateKey"));

        return $this->_kernel->generatePage("GET", $systemParams, $bizParams, $textParams, $sign);
    }
}